'''
Copyright 2010 Indra Bagus <indra.bagus@gmail.com> 
    
Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. 
'''
from Type import WmxDictionaryValue, WmxIntegerValue, WmxStringValue
from Dictionary import ULMAPDict


class ULMapIE(object):
    def __init__(self,uiuc):
        assert(isinstance(uiuc,int) or isinstance(uiuc,long))
        self.cid   = int()
        self.uiuc  = WmxIntegerValue()
        self.uiuc.val = uiuc
        self.uiuc.strinfo = ULMAPDict.GetUIUCInfo(uiuc)
        

class ULMapIEFastFeedBack(ULMapIE):
    def __init__(self):
        super(ULMapIEFastFeedBack,self).__init__(0)
        self.symbol_offset      = int()
        self.subchannel_offset  = int()
        self.no_ofdma_symbols   = int()
        self.no_subchannels     = int()
        self.reserved           = int()
        
class ULMapIEBurstProfile(ULMapIE):
    def __init__(self,uiuc):
        super(ULMapIEBurstProfile,self).__init__(uiuc)
        self.duration           = int()
        self.repet_coding_ind   = WmxDictionaryValue(ULMAPDict.repetion_coding_ind)
        self.aas_amc_zone_mode  = False
        self.slot_offset        = WmxIntegerValue()
    
    
        
class ULMapIECDMABRequestAndRanging(ULMapIE):
    def __init__(self):
        super(ULMapIECDMABRequestAndRanging,self).__init__(12)
        self.ofdma_symbol_offset            = 0
        self.subchannel_offset              = 0
        self.no_ofdma_symbols               = 0
        self.no_subchannels                 = 0
        self.ranging_method                 = WmxIntegerValue()
        self.dedicated_ranging_indicator    = WmxIntegerValue()
        


class ULMapIECDMAAllocation(ULMapIE):
    def __init__(self):
        super(ULMapIECDMAAllocation,self).__init__(14)
        self.duration               = WmxIntegerValue()
        self.uiuc_transmission      = WmxIntegerValue()
        self.repet_coding_ind       = WmxIntegerValue()
        self.frame_number_index     = WmxIntegerValue()
        self.ranging_code           = WmxIntegerValue()
        self.ranging_symbol         = WmxIntegerValue()
        self.ranging_subchannel     = WmxIntegerValue()
        self.bw_req_mandatory       = WmxIntegerValue()



class ULMapIEPAPRReductionSafetySoundingZone(ULMapIE):
    def __ini__(self):
        super(ULMapIEPAPRReductionSafetySoundingZone,self).__init__(13)
        self.ofdma_symbol_offset        = int()
        self.subchannel_offset          = int()
        self.no_ofdma_symbols           = int()
        self.no_subchannel_sz_shift     = int()
        self.papr_reduction_safety_zone = WmxIntegerValue()
        self.sounding_zone              = WmxIntegerValue()
        self.reserved                   = int()



class ULMapIEExtended(ULMapIE):
    def __init__(self,ext_uiuc,length):
        super(ULMapIEExtended,self).__init__(15)
        assert(isinstance(ext_uiuc,int) or isinstance(ext_uiuc,long()))
#       assert(isinstance(length,int) or isinstance(length,long()))
        self.ext_uiuc           = WmxIntegerValue()
        self.ext_uiuc.val       = ext_uiuc
        self.ext_uiuc.strinfo   = ULMAPDict.GetExtendedUIUC(ext_uiuc)
        self.length             = length

        

class ULMapIEPowerControl(ULMapIEExtended):
    def __init__(self):
        super(ULMapIEPowerControl,self).__init__(0x00,0x02)
        self.power_control              = WmxIntegerValue()
        self.power_measurement_frame    = WmxIntegerValue()


                
class ULMapIE_AAS_UL(ULMapIEExtended):
    def __init__(self):
        super(ULMapIE_AAS_UL,self).__init__(0x02,0x03)
        self.permutation        = WmxIntegerValue() # 2 bit
        self.ul_perm_base       = WmxIntegerValue() # 7 bit
        self.symbol_offset      = WmxIntegerValue() # 8 bit
        self.aas_zone_length    = WmxIntegerValue() # 8 bit
        self.ul_preamble_config = WmxIntegerValue() # 2 bit;
        self.reserved           = WmxIntegerValue() # 5 bit;
        
        
        
class ULMapIE_CQICHAllocation(ULMapIEExtended):
    def __init__(self,length):
        super(ULMapIE_CQICHAllocation,self).__init__(0x03,length)
        self.cqich_id                           = WmxIntegerValue()
        self.alloc_offset                       = WmxIntegerValue()
        self.period                             = WmxIntegerValue()
        self.frame_offset                       = WmxIntegerValue()
        self.duration                           = WmxIntegerValue()
        self.report_conf_included               = WmxIntegerValue()
        self.feedback_type                      = WmxIntegerValue()
        self.report_type                        = WmxIntegerValue()
        self.cinr_preamble_report_type          = WmxIntegerValue()
        self.zone_permutation                   = WmxIntegerValue()
        self.zone_type                          = WmxIntegerValue()
        self.zone_prbs_id                       = WmxIntegerValue()
        self.major_group_ind                    = WmxIntegerValue()
        self.pusc_major_group_bitmap            = WmxIntegerValue()
        self.cinr_zone_meas_type                = WmxIntegerValue()
        self.averaging_param_incl               = WmxIntegerValue()
        self.averaging_param                    = WmxIntegerValue()
        self.mimo_permutation_feedback_cycle    = WmxIntegerValue()
        self.padding                            = WmxIntegerValue()



class ULMapIEUplinkZone(ULMapIEExtended):
    def __init__(self):
        super(ULMapIEUplinkZone,self).__init__(0x04,0x03)
        self.ofdma_symbol_offset        = WmxIntegerValue()
        self.permutation                = WmxIntegerValue()
        self.ul_permbase                = WmxIntegerValue()
        self.amc_type                   = WmxIntegerValue()
        self.use_all_subch              = WmxIntegerValue()
        self.disable_subch_rotation     = WmxIntegerValue()
        self.hfdd_over_subframe_alloc   = WmxIntegerValue()
        self.hfdd_inter_ul_gap_alloc    = WmxIntegerValue()
        self.reserved                   = WmxIntegerValue()



class ULMapIEPhysicalModifier(ULMapIEExtended):
    def __init__(self):
        super(ULMapIEPhysicalModifier,self).__init__(0x05,0x01)
        self.preamble_modifier_type         = WmxIntegerValue()
        self.preamble_frequency_shift_index = WmxIntegerValue()
        self.preamble_time_shift_index      = WmxIntegerValue()
        self.pilot_pattern_modifier         = WmxIntegerValue()
        self.pilot_pattern_index            = WmxIntegerValue()



class ULMapIEFastTrackingIE(ULMapIEExtended):
    def __init__(self,length):
        super(ULMapIEFastTrackingIE,self).__init__(0x07,length)
        self.map_index  = WmxIntegerValue()
        self.reserved   = WmxIntegerValue()
        
        #list of fast tracking ie tuple
        self._listparam = []
        self._iter      = iter(self._listparam)
        
    def GetFastTrackingIterator(self):
        return iter(self._listparam)
    
    
    def PushFastTrackingCorrection(self,pow,freq,time):
        retval = [WmxIntegerValue(),WmxIntegerValue(),WmxIntegerValue()]
        retval[0].val = int(pow)
        retval[0].strinfo = ULMAPDict.GetPowCorrectionIndInfo(int(pow))
        retval[1].val = int(freq)
        retval[2].val = int(time)
        self._listparam.append((int(pow),int(freq),int(time)))
                               
    

class ULMapIE_ULPUSCBurstAlloc(ULMapIEExtended):
    def __init__(self):
        super(ULMapIE_ULPUSCBurstAlloc,self).__init__(0x08,0x05)
        self.uiuc                   = WmxIntegerValue()
        self.segment                = WmxIntegerValue()
        self.ul_permbase            = WmxIntegerValue()
        self.ofdma_symbol_offset    = WmxIntegerValue()
        self.subchannel_offset      = WmxIntegerValue()
        self.duration               = WmxIntegerValue()
        self.repet_coding_ind       = WmxIntegerValue()
        self.reserved               = WmxIntegerValue()
                           


class ULMapIEFastRanging(ULMapIEExtended):
    def __init__(self,length):
        super(ULMapIEFastRanging,self).__init__(0x09,length)
        self.ho_id_ind          = WmxIntegerValue()
        self.reserved           = WmxIntegerValue()
        self.ho_id              = WmxIntegerValue()
        self.mac_address        = WmxStringValue()
        self.uiuc               = WmxIntegerValue()
        self.duration           = WmxIntegerValue()
        self.repet_coding_ind   = WmxIntegerValue()
        
        
        
class ULMapIEULAllocationStart(ULMapIEExtended):
    def __init__(self):
        super(ULMapIEULAllocationStart,self).__init__(0x0A,0x02)
        self.symbol_offset          = WmxIntegerValue()
        self.subchannel_offset      = WmxIntegerValue()
        self.hfdd_ul_subframe_ind   = WmxIntegerValue()
                              

            